package com.quasar.hpatient.module.comm_album_folder;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;

import com.quasar.hpatient.R;
import com.quasar.hpatient.bean.comm_album.AlbumFolderBean;
import com.quasar.hpatient.module.comm_album.AlbumActivity;

import java.util.Map;

import lib.quasar.base.frame.BaseFragment;

/**
 * description: 选择图片, 相册集合
 * created by kalu on 2018/4/18 15:53
 */
public class AlbumFolderFragment extends BaseFragment<AlbumFolderPresenter> implements View.OnClickListener, AlbumFolderView {

    @Override
    public int initView() {
        return R.layout.fragment_comm_album_folder;
    }

    @Override
    public void initDataLocal() {

        View view = getView();
        if (null == view) return;

        AlbumFolderPresenter presenter = getPresenter();
        if (null == presenter) return;
        presenter.initLayoutData(getContext().getApplicationContext(), this);
    }

    @Override
    public void initDataNet() {
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        }
    }

    @Override
    public void setRecycler(boolean refresh, RecyclerView.Adapter adapter, RecyclerView.LayoutManager manager, RecyclerView.ItemDecoration decoration) {

        if (null == getView()) return;

        final RecyclerView recycler = getView().findViewById(R.id.fragment_album_folder_recycler);
        if (null == recycler) return;

        if (refresh) {
            recycler.getAdapter().notifyDataSetChanged();
        } else {
            recycler.setLayoutManager(manager);
            if (null != decoration) {
                recycler.addItemDecoration(decoration);
            }
            recycler.setAdapter(adapter);
        }
    }

    @Override
    public void setPhotoList(Map<String, AlbumFolderBean> map) {

        AlbumFolderPresenter presenter = getPresenter();
        if (null == presenter) return;
        presenter.insertPhoto(this, map);
    }

    @Override
    public void switchFolder(String folder) {

        if (TextUtils.isEmpty(folder) || null == getActivity() || !(getActivity() instanceof AlbumActivity))
            return;

        AlbumActivity activity = (AlbumActivity) getActivity();
        activity.changeFolder(folder);
    }
}